package com.hxk.juc.thread.syn8d;

import java.util.concurrent.TimeUnit;

/**
 * //结论，synchronized (this)锁的整个对象，这里必须是ｍ１方法执行完后在执行ｍ２
 */
public class SynchronizedCase2 {

    public synchronized void m1(){
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m1");
    }

    public void m2(){
        synchronized (this){
            System.out.println("m2");
        }
    }

    public static void main(String[] args) {

        SynchronizedCase2 case2 = new SynchronizedCase2();

        new Thread(()->{
            case2.m1();
        },"001").start();

        new Thread(()->{
            case2.m2();
        },"002").start();

    }
}
